package vip.xiaonuo.supplier.modular.base.stores.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.base.stores.entity.SupplierStores;
import vip.xiaonuo.supplier.modular.base.stores.param.SupplierStoresAddParam;
import vip.xiaonuo.supplier.modular.base.stores.param.SupplierStoresEditParam;
import vip.xiaonuo.supplier.modular.base.stores.param.SupplierStoresIdParam;
import vip.xiaonuo.supplier.modular.base.stores.param.SupplierStoresPageParam;
import vip.xiaonuo.supplier.modular.base.stores.service.SupplierStoresService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 门店（仓库）信息控制器
 *
 * @author Mr.wu
 * @date  2025/03/15 18:35
 */
@Tag(name = "门店（仓库）信息控制器")
@RestController
@Validated
public class SupplierStoresController {

    @Resource
    private SupplierStoresService supplierStoresService;

    /**
     * 获取门店（仓库）信息分页
     *
     * @author Mr.wu
     * @date  2025/03/15 18:35
     */
    @Operation(summary = "获取门店（仓库）信息分页")
    @SaCheckPermission("/supplier/base/stores/page")
    @GetMapping("/supplier/base/stores/page")
    public CommonResult<Page<SupplierStores>> page(SupplierStoresPageParam supplierStoresPageParam) {
        return CommonResult.data(supplierStoresService.page(supplierStoresPageParam));
    }

    /**
     * 添加门店（仓库）信息
     *
     * @author Mr.wu
     * @date  2025/03/15 18:35
     */
    @Operation(summary = "添加门店（仓库）信息")
    @CommonLog("添加门店（仓库）信息")
    @SaCheckPermission("/supplier/base/stores/add")
    @PostMapping("/supplier/base/stores/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierStoresAddParam supplierStoresAddParam) {
        supplierStoresService.add(supplierStoresAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑门店（仓库）信息
     *
     * @author Mr.wu
     * @date  2025/03/15 18:35
     */
    @Operation(summary = "编辑门店（仓库）信息")
    @CommonLog("编辑门店（仓库）信息")
    @SaCheckPermission("/supplier/base/stores/edit")
    @PostMapping("/supplier/base/stores/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierStoresEditParam supplierStoresEditParam) {
        supplierStoresService.edit(supplierStoresEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除门店（仓库）信息
     *
     * @author Mr.wu
     * @date  2025/03/15 18:35
     */
    @Operation(summary = "删除门店（仓库）信息")
    @CommonLog("删除门店（仓库）信息")
    @SaCheckPermission("/supplier/base/stores/delete")
    @PostMapping("/supplier/base/stores/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierStoresIdParam> supplierStoresIdParamList) {
        supplierStoresService.delete(supplierStoresIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取门店（仓库）信息详情
     *
     * @author Mr.wu
     * @date  2025/03/15 18:35
     */
    @Operation(summary = "获取门店（仓库）信息详情")
    @SaCheckPermission("/supplier/base/stores/detail")
    @GetMapping("/supplier/base/stores/detail")
    public CommonResult<SupplierStores> detail(@Valid SupplierStoresIdParam supplierStoresIdParam) {
        return CommonResult.data(supplierStoresService.detail(supplierStoresIdParam));
    }

    /**
     * 获取仓库信息列表
     *
     * @author Mr.wu
     * @date  2024/10/23 20:57
     */
    @Operation(summary = "获取仓库信息列表")
    @SaCheckPermission("/supplier/base/stores/storesList")
    @GetMapping("/supplier/base/stores/storesList")
    public CommonResult<List<SupplierStores>> storesList() {
        return CommonResult.data(supplierStoresService.storeslist());
    }

    /**
     * 获取门店仓库信息树
     *
     * @author Mr.wu
     * @date  2024/10/23 20:57
     */
    @Operation(summary = "获取门店仓库信息树")
    @SaCheckPermission("/supplier/base/stores/storesTree")
    @GetMapping("/supplier/base/stores/storesTree")
    public CommonResult<List<Tree<String>>> storesTree() {
        return CommonResult.data(supplierStoresService.storesTree());
    }
}
